package com.chzu.service;

import com.chzu.mapper.DataSourceMapper;
import com.chzu.pojo.DataSource;
import com.chzu.utils.JdbcUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.List;

/**
 * @author liangzhuo
 * @create 2021-10-21-18:00
 */
@SpringBootTest
@RunWith(SpringRunner.class)
public class ServiceTestes {

    @Autowired
    private IDataSourceService dataSourceService;
    @Autowired
    private DataSourceMapper dataSourceMapper;

//    JdbcUtils jdbcUtils = new JdbcUtils();

    @Test
    public void getAllDataSource() {
        System.out.println(dataSourceService.getAllDataSource());
    }

    @Test
    public void getConnection() {
        String driverClassName = "com.mysql.cj.jdbc.Driver";
        String url = "jdbc:mysql://localhost:3306/saas_cloud_000?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=Asia/Shanghai";
        String userName = "root";
        String password = "123456";
        int i = JdbcUtils.testConnect(url, driverClassName, userName, password);
        System.out.println(i);
    }

    @Test
    public void getConnection2() {
        List<DataSource> list = dataSourceService.list();
        JdbcUtils.initCache(list);
    }

    @Test
    public void getAllTables() {
        List list = dataSourceService.getAlltables();
        System.out.println(list);
    }

    @Test
    public void selectAlltabales() {
        List list = dataSourceMapper.selectAllTables();
        System.out.println(list);
    }
}
